package com.example.myapplication.main

import androidx.lifecycle.viewModelScope
import com.example.myapplication.TestResult
import com.example.myapplication.TestUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import org.hades.corelib.base.extend.doLaunch
import org.hades.corelib.base.vm.CoreViewModel
import javax.inject.Inject

@HiltViewModel
class MainViewModel @Inject constructor(
    private val testUseCase: TestUseCase
) : CoreViewModel() {
    private var ui: MutableStateFlow<TestResult> = MutableStateFlow(TestResult(""))
    var uiFlow: StateFlow<TestResult> = ui.asStateFlow()

    fun getCash() {
        doLaunch {
            testUseCase.invoke(TestUseCase.Params("测试"))
                .map {
                    it.apply {
                        str += "动下手脚"
                    }
                }
                .composeNomal()
                .launchIn(this)
        }
    }

    fun sendStateFlowMessage() {
        ui.tryEmit(TestResult("发送数据～～"))
    }

}